<?php
/**
 * 联盟平台
 *
 * @category   Union
 * @package    Union_Db
 * @subpackage Table
 * @copyright  Locke
 * @version    $Id: Abstract.php 6320 2007-09-12 00:27:22Z bkarwin $
 */

abstract class Union_Db_Table_Abstract extends Zend_Db_Table_Abstract
{
    /**
     * 默认是假删除
     */
    public function delete($where)
    {
        $data = array(
            'Update_Date' => date('Y-m-d h:m:s'),
            'Deleted' => 1
        );
        $row = $this->createRow($data);
        
        return $this->update($row->toArray(), $where);
    }
    
    /**
     * 真删除
     */
    public function real_delete($where)
    {
        parent::delete($where);
    }
    
    /**
     * 插入，自动添加创建时间这个字段
     */
    public function insert(array $data)
    {
        if(!isset($data['Create_Date']))
        {
            $data['Create_Date'] = date('Y-m-d h:m:s');
        }
        $row = $this->createRow($data);

        return parent::insert($row->toArray());
    }    
    
    /**
     * 更新，自动添加更新时间这个字段
     */
    public function update(array $data, $where)
    {
        if(!isset($data['Update_Date']))
        {
            $data['Update_Date'] = date('Y-m-d h:m:s');
        }
        $row = $this->createRow($data);
        
        return parent::update($row->toArray(), $where);
    }
    
}
?>